home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / pjp / oispoint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-02  |  656 b   |  33 lines

  1. ------------------ Listing 3: The file osipoint.c -------------
  2.  
  3. // osipoint -- ostream::operator<<(void *)
  4. #include <ostream>
  5.  
  6. ostream& ostream::operator<<(void *x)
  7.     {    // insert a void *
  8.     _TRY_IO_BEGIN
  9.     if (!opfx())
  10.         setstate(badbit);
  11.     else
  12.         {    // put pieces of pointer
  13.         const int NL = 1 +
  14.             (sizeof (void *) - 1) / sizeof (unsigned long);
  15.         union {
  16.             void *pv;
  17.             unsigned long lo[NL];
  18.             } u;
  19.         u.lo[NL - 1] = 0, u.pv = x;
  20.         for (int i = 0; ; )
  21.             {    // put ints separated by colons
  22.             _Print("B lx", u.lo[i]);
  23.             if (NL <= ++i)
  24.                 break;
  25.             rdbuf()->sputc(':');
  26.             }
  27.         }
  28.     osfx();
  29.     _CATCH_IO_END
  30.     return (*this);
  31.     }
  32.  
  33.